//Wrong answer
#include <algorithm>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <set>
#include <map>

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

using namespace std;

int t, n, m, i, j, a, b, r[100];
bool dep[100][100];

bool comp(const int x, const int y){
	if(dep[y][x])return 1;
	else{
		return x<y;
	}
}
void bubblesort(){
	for(j= n-1; j>0; j--){
		for(i=0;i<j;i++){
			if(dep[ r[i] ][ r[i+1] ]){
				swap(r[i+1], r[i]);
			}
			else if(r[i+1] < r[i]){ 
				swap(r[i+1], r[i]);
			}
		}
	}
}
void read(){
	memset(dep, 0, sizeof(dep));
	
	scanf("%d%d", &n, &m);
	for(i=0;i<m;++i){
		scanf("%d%d", &a, &j);
		--a;
		while(j--){
			scanf("%d", &b);
			--b;
			dep[a][b]=1;
		}
	}
}
void process(){
	for(i=0;i<n;++i)r[i]=i;
	//sort_heap(r,r+n, comp);
	bubblesort();
	
	printf("%d", r[0]+1);
	for(i=1;i<n;++i)printf(" %d", r[i]+1);
	printf("\n");
}

int main(){
	freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);
	
	scanf("%d", &t);
	while(t--){
		read();
		process();
	}
	return 0;
}
